<template>
	<div id="test">
		<button @click="submit(fileName)">测试按钮-获取</button>
		<div>用户空间文件结构信息:</div>
		
		<span v-for="data in index2">
			<span @click="">/{{data}}</span>
		</span>
		
		<div v-for="data in index">
			<div @click="submit(data.FileName)">文件名：{{data.FileName}} 创建日期：{{data.Filetime}}</div>
		</div>
		<br>
		<button @click="back">返回上一级</button>
		
	</div>
</template>

<script>
	import axios from 'axios'
	import Vue from 'vue'
	import Router from 'vue-router'
	
	Vue.use(Router)

	const commonRoutes = [
	    {
	        path: '/login',
	        name: 'login',
	        meta: { title: '登录' },
	        component: () => import('../components/Login.vue'),
	    },
	    {
	        path: '/other', 
	        name: 'other',
	        meta: { title: '单独的路由' },
	        component: () => import('../components/small1.vue'),
	    },
	    {
	        path: '/404',
	        name: '404',
	        meta: { title: '404' },
	        component: () => import('../components/404.vue'),
	    },
	    { path: '/', redirect: '/login' },
	]

	export default{

		data(){
			return{
				// json:this.response.data;
				index:[],
				index2:[''],
				fileName:'/',
				url:'/api/file/filelist?userName=scott&parentPath=',
				newURL:'',
				temp:'',
				asyncRoutes:{
				    home: {
				        path: 'home',
				        name: 'home',
				        meta: { title: '主页' },
				        // component: () => import('../components/Index.vue'),
				    },
				    t1: {
				        path: 't1',
				        name: 't1',
				        meta: { title: '其他' },
				        // component: () => import('../components/small1.vue'),
				    },
				    password: {
				        path: 'password',
				        name: 'password',
				        meta: { title: '修改密码' },
				        // component: () => import('../views/Password.vue'),
				    }
				},
				
			
				
			}
		},
		
		
		methods:{
			
			request(URL){
				axios({
				  method:'post',
				  url:URL,
				}).then(response => {
					  this.index = response.data;
					  console.log(response.data);
				});
			},
			
			submit(FileName){
				if(FileName=='/'){
					this.index2=[];
					this.newURL = '/api/file/filelist?userName=scott&parentPath=/'
				}else{
					this.index2.push(FileName);
					if(this.newURL != '/api/file/filelist?userName=scott&parentPath=/')
						this.newURL = this.newURL + ('/'+FileName.toString());
					else
						this.newURL = this.newURL +FileName.toString();
				}
				console.log(this.newURL);

				this.request(this.newURL);
				
			},
			
			
			
			back(){
				this.index2.pop();
			},
			
			
			
			
			generateRoutes(children, item) {
			    if (item.name) {
			        if (asyncRoutes[item.name]) 
						children.push(asyncRoutes[item.name])
			    } else if (item.children) {
			        item.children.forEach(e => {
			            generateRoutes(children, e)
			        })
			    }
			},
			
			
			createRoutes(data) {
			    const result = []
			    const children = []
			
			    result.push({
			        path: '/',
			        component: () => import('../components/Index.vue'),
			        children,
			    })
			
			    data.forEach(item => {
			        generateRoutes(children, item)
			    })
			
			    // 最后添加404页面
			    result.push(
			        { path: '*', redirect: '/404' },
				)
			    return result
			},
			
			
			resetRouter() {
			    const newRouter = createRouter()
			    router.matcher = newRouter.matcher
			},
			
			
			createRouter:() => new Router({
			    routes: commonRoutes,
			})
			
		},
		
		

		created(){
			// const router = createRouter()
			console.log("created调用成功")
			this.index2=[];
			this.newURL = '/api/file/filelist?userName=scott&parentPath=/'
			this.request("/api/file/filelist?userName=scott&parentPath=/");
			
			// const router = this.createRouter()
		}
		
}
</script>

<style>
</style>
